﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.IO;

namespace EmployeeCheckIn
{
    public class EditTimeUpdate
    {
        public string total(string s)
        {
            int HH;
            int mm;
            int ss;

            string[] stemp = s.Split(':');
            HH = Convert.ToInt32(stemp[0]);
            mm = Convert.ToInt32(stemp[1]);
            ss = Convert.ToInt32(stemp[2]);

            string overtime_str = ((HH * 60) + (mm) + (ss / 60)).ToString();
            return overtime_str;
        }

        public int ReLateTime(string AfterTime,string StartTime) 
        {
            int LateTime = 0;
            string date1 = Convert.ToDateTime(StartTime).ToString(" HH:mm ");
            string[] stemp1 = date1.Split(':');
            int HH = Convert.ToInt32(stemp1[0]);
            int mm = Convert.ToInt32(stemp1[1]);

            string date2 = Convert.ToDateTime(AfterTime).ToString(" HH:mm ");
            string[] stemp2 = date2.Split(':');
            int HH1 = Convert.ToInt32(stemp2[0]);
            int mm1 = Convert.ToInt32(stemp2[1]);

            if (HH1 < HH)
            {
               LateTime =  0;
            }
            if (HH1 > HH)
            {
                string count = (Convert.ToDateTime(AfterTime) - Convert.ToDateTime(StartTime)).ToString();
                LateTime = Convert.ToInt32(total(count));
            }
            if (HH1 == HH)
            {

                if (mm1 > mm)
                {
                    string count = (Convert.ToDateTime(AfterTime) - Convert.ToDateTime(StartTime)).ToString();
                    LateTime = Convert.ToInt32(total(count));
                }
                else
                {
                    LateTime = 0;
                }
                
            }

             return LateTime;
        }

        public int ReLateTime(DateTime DAfterTime, DateTime DStartTime)
        {
            string StartTime = DStartTime.ToString();
            string AfterTime = DAfterTime.ToString();
            int LateTime = 0;
            string date1 = Convert.ToDateTime(StartTime).ToString(" HH:mm ");
            string[] stemp1 = date1.Split(':');
            int HH = Convert.ToInt32(stemp1[0]);
            int mm = Convert.ToInt32(stemp1[1]);

            string date2 = Convert.ToDateTime(AfterTime).ToString(" HH:mm ");
            string[] stemp2 = date2.Split(':');
            int HH1 = Convert.ToInt32(stemp2[0]);
            int mm1 = Convert.ToInt32(stemp2[1]);

            if (HH1 < HH)
            {
                LateTime = 0;
            }
            if (HH1 > HH)
            {
                string count = (Convert.ToDateTime(AfterTime) - Convert.ToDateTime(StartTime)).ToString();
                LateTime = Convert.ToInt32(total(count));
            }
            if (HH1 == HH)
            {

                if (mm1 > mm)
                {
                    string count = (Convert.ToDateTime(AfterTime) - Convert.ToDateTime(StartTime)).ToString();
                    LateTime = Convert.ToInt32(total(count));
                }
                else
                {
                    LateTime = 0;
                }

            }

            return LateTime;
        }

        ////////////////////////////////

    }
}